package com.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.distribute.common.util.ExcelUtils;


public class Demo {
	public static void main(String[] args) throws Exception {
		// 保存路径
		String savePath = ".";
		// 文件名称
		String fileName = "poi-test";
		// 第一行表格的总名称
		String sheetTitle = "测试bbbbb";
		// 底部表格名称
		String sheetName = "测试aaaa";

		// 模拟要导出的数据
		List<Map<String, Object>> allList = new ArrayList<Map<String, Object>>();// 要导出的数据
		Map<String, Object> item = new HashMap<String, Object>();
		item.put("id", 1);
		item.put("name", "王佳佳");
		item.put("company", "XXX有限公司");
		item.put("phone", "13111111111");
		item.put("email", "xxx@qq.com");
		item.put("province", "广东省");
		item.put("address", "XXXXXXXX街道41号");
		allList.add(item);
		List<String> columnNames = new LinkedList<>();
		columnNames.add("ID");
		columnNames.add("姓名");
		columnNames.add("公司");
		columnNames.add("手机");
		columnNames.add("电子邮件");
		columnNames.add("地区(省份)");
		columnNames.add("联系地址");

		ExcelUtils exportExcel2007 = new ExcelUtils();
		exportExcel2007.writeExcelTitle(savePath, fileName, sheetName, columnNames, sheetTitle);

		for (int j = 0; j < 1; j++) {
			List<List<Object>> objects = new LinkedList<>();
			for (int i = 0; i < allList.size(); i++) {
				Map<String, Object> busiUser = allList.get(i);
				List<Object> dataA = new LinkedList<>();
				dataA.add(busiUser.get("id"));
				dataA.add(busiUser.get("name"));
				dataA.add(busiUser.get("company"));
				dataA.add(busiUser.get("phone"));
				dataA.add(busiUser.get("email"));
				dataA.add(busiUser.get("province"));
				dataA.add(busiUser.get("address"));
				objects.add(dataA);
			}

			try {
				exportExcel2007.writeExcelData(savePath, fileName, sheetName, objects);
			} catch (IOException e) {
				e.printStackTrace();
			}
			objects.clear();
		}
		exportExcel2007.dispose();// 释放资源
		System.out.println("生成excel文档成功，所在路径：" + savePath +"\\"+ fileName + ".xlsx");
	}
}
